package com.zs.mp.controller;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zs.mp.dao.IUserMapper;
import com.zs.mp.model.User;
import com.zs.mp.model.UserDTO;
import com.zs.mp.model.vo.UserVO;
import com.zs.mp.service.IUserService;

import jakarta.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
	
	@Resource
	private IUserService userService;
	
	@GetMapping("/list")
	public List<User> listUser(){
		// User中的gender属性是Gender枚举类型,mybatis自定义类型处理器会将数据库字段类型转换为Gender类型，因此Java类中的gender属性存储的就是整个枚举（如：FEMALE("0","女"),MALE("1","男")）
		List<User> list = userService.list();
		return list;
	}
	
	
	@GetMapping("/listgt")
	public List<User> listUserByGt(){
		LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
		lqw.gt(User::getId, 2);
		List<User> list = userService.getBaseMapper().selectList(lqw);
		return list;
	}
	
	@GetMapping("/userid")
	public User getUserById(@RequestParam(name = "id") Integer userId) {
		User user = userService.getUserById(userId);
		return user;
	}
	
	@PostMapping("/list/condition")
	public List<User> listUserByCondition(@RequestBody UserDTO userDTO){
		List<User> list = userService.listUserByCondition(userDTO);
		return list;
	}
	
}
